#include <stdio.h>
#include <string.h>

#define STDIN
//#define DEBUG

short int table[26][6];
int count_len_n[6];
char word[6];
int word_len;

void compute(int ch, int len)
{
    int x;
    int sum = 0;
    for (x = ch+1; x <= 'z'; ++x)
    {
        sum += table[x-'a'][len-1];
    }
    table[ch-'a'][len] = sum;
}

void  count()
{
    int cnt = 0;
    int x_ch;

    int i;
    for (i = 1; i < word_len; ++i)
    {
        cnt += count_len_n[i];
    }

    int pre_ch = 'a'-1;//特殊处理为首字符设置
    int pos = 0;

    while(pos < word_len)
    {
        if (pre_ch >= word[pos])
        {
            cnt = -1;
            break;
        }
        for (x_ch = pre_ch+1; x_ch < word[pos]; x_ch++)
        {
            cnt += table[x_ch-'a'][word_len - pos];
#ifdef DEBUG
            printf("pos: %d pre_ch: %c x_ch: %c cnt: %d, + %d\n", pos, pre_ch, x_ch, cnt, table[x_ch-'a'][word_len-pos]);
#endif
        }
        pre_ch = word[pos], pos++;
    }
    printf("%d\n", cnt+1);
}

int main()
{
#ifdef STDIN
    freopen("bin/1496.in", "r", stdin);
#endif

    int i;

    for (i = 0; i < 26; ++i)
        table[i][1] = 1;


    int len, ch;
    for (len = 2; len <= 5; ++len)
    {
        for (ch = 'a'; ch <= 'z'; ++ch)
        {
            compute(ch, len);
        }
    }

    for (len = 1, count_len_n[len] = 0; len <= 5; len++)
    {
        for (ch = 'a'; ch <= 'z'; ch++)
            count_len_n[len] += table[ch-'a'][len];
    }
#ifdef DEBUG
    for(ch = 'a'; ch <= 'z'; ch++)
    {
        for (len = 1; len <= 5; len++)
        {
            printf("%4d ", table[ch-'a'][len]);
        }
        printf("\n");
    }
    for (len = 1; len <= 5; len++)
    {
        printf("%4d ", count_len_n[len]);
    }
    printf("\n");
#endif

    while(scanf("%s", word) != EOF)
    {
        if (word[0] == ' ' || word[0] == '\0')
            continue;
#ifdef DEBUG
        printf("word: %s\n", word);
#endif

        word_len = strlen(word);

        count();
    }

    return 0;
}
